package com.shujia.day13;

public class Demo04Priority {
    public static void main(String[] args) {
        /*
            TODO:
                优先权对线程执行的影响?
                ① 设置优先权
                    => 优先级设置时需要在1-10之间  => 值越大优先级越高
                      注意:对于优先级高的不一定先执行 获取到CPU的执行权可能性更高 具有一定的随机性

         */
//        PriorityThread thread1 = new PriorityThread("李玉龙");
//        thread1.setPriority(10);
//        PriorityThread thread2 = new PriorityThread("李亮");
//        thread2.setPriority(9);
//        PriorityThread thread3 = new PriorityThread("李国涛");
//        thread3.setPriority(8);
//
//        thread2.start();
//        thread1.start();
//        thread3.start();


        PriorityThread thread1 = new PriorityThread("李玉龙");
        thread1.setPriority(1);
        PriorityThread thread2 = new PriorityThread("李亮");
        thread2.setPriority(2);
        PriorityThread thread3 = new PriorityThread("李国涛");
        thread3.setPriority(3);

        thread2.start();
        thread1.start();
        thread3.start();
    }

    static class PriorityThread extends Thread{
        public PriorityThread(String name) {
            super(name);
        }

        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                System.out.println("当前线程名称:" + this.getName());
                System.out.println("当前线程优先权:" + this.getPriority());
            }
        }
    }

}
